package com.hymns;

import java.io.IOException;

import org.xml.sax.SAXException;

import android.app.Activity;
import android.content.res.Resources.NotFoundException;
import android.os.Bundle;
import android.widget.TextView;

import com.hymns.domain.Hymn;
import com.hymns.utils.XmlParser;

public class HymnActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.hymn_content);

		Bundle extras = getIntent().getExtras();

		if (extras != null) {

			String fileName = getResources().getString(R.string.fileName);

			fileName = extras.getString(fileName);

			Hymn hymn;

			try {
				hymn = XmlParser.getSingletonParser().getHymn(fileName,
						getResources().openRawResource(R.raw.hymn_1));

				set_TextViewText(R.id.textViewTitle, hymn.get_FormatedTitle());

				set_TextViewText(R.id.textViewContent, hymn.get_Content());

			} catch (NotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SAXException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}

	private void set_TextViewText(int id, String text) {

		TextView tv = (TextView) findViewById(id);

		tv.setText(text);
	}
}
